/*
 * Copyright 2019, create by cx.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* eslint require-jsdoc: "off" */
/* eslint valid-jsdoc: "off" */
// /* global  :true */

const mysql = require('mysql2')
const config = require('./db-config')

let connection = null

function handleDisconnect() {

  connection = mysql.createPool(config.mysql_connection_options);
  let getConnection = function (callback){
    connection.getConnection(function (err, connection) {
      if(err) console.log("connection err",err);
      // 回调处理逻辑
      callback(err,connection);
    });
  };
  exports.getConnection = getConnection;
}

handleDisconnect()

exports.handleDisconnect = handleDisconnect
